package com.lwt.monstermall.search.controller;

import com.lwt.monstermall.common.exception.BizCodeEnum;
import com.lwt.monstermall.common.to.es.SkuEsModel;
import com.lwt.monstermall.common.utils.R;
import com.lwt.monstermall.search.service.ProdcutSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: monstermall
 * @author: 大怪
 * @create: 2022-02-14 20:39
 */
@Slf4j
@RestController
@RequestMapping("/search/save")
public class ElasticSaveController {

    @Autowired
    ProdcutSaveService prodcutSaveService;


    //上架商品
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModes){
        boolean b = false;
        try {
            b = prodcutSaveService.productStatusUp(skuEsModes);
        }catch (Exception e){
            log.error("ElasticSaveController商品上架错误：{}",e);
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }

        if (!b){
            return R.ok();
        }else {
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }

    }
}
